/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.eclipse.persistence.annotations.CascadeOnDelete;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "MashSchedule")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MashSchedule.findAll", query = "SELECT m FROM MashSchedule m"),
    @NamedQuery(name = "MashSchedule.findByScheduleID", query = "SELECT m FROM MashSchedule m WHERE m.scheduleID = :scheduleID"),
    @NamedQuery(name = "MashSchedule.findByDescription", query = "SELECT m FROM MashSchedule m WHERE m.description = :description")})
public class MashSchedule implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "scheduleID")
    private Integer scheduleID;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 50)
    @Column(name = "description")
    private String description;
    @OneToMany(cascade=CascadeType.ALL, orphanRemoval = true)
    @CascadeOnDelete
    @JoinTable(
        name="JTMashScheduleToStep",
        joinColumns={ @JoinColumn(name="scheduleID", referencedColumnName="scheduleID")},
        inverseJoinColumns={ @JoinColumn(name="stepID", referencedColumnName="stepID", unique=true)}
    )
    private List<MashStep> mashStepCollection;
    @OneToMany(mappedBy = "mashSchedule")
    private Collection<Recipes> recipesCollection;

    public MashSchedule() {
    }

    public MashSchedule(Integer scheduleID) {
        this.scheduleID = scheduleID;
    }

    public MashSchedule(Integer scheduleID, String description) {
        this.scheduleID = scheduleID;
        this.description = description;
    }

    public Integer getScheduleID() {
        return scheduleID;
    }

    public void setScheduleID(Integer scheduleID) {
        this.scheduleID = scheduleID;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public List<MashStep> getMashStepCollection() {
        return mashStepCollection;
    }

    public void setMashStepCollection(List<MashStep> mashStepCollection) {
        this.mashStepCollection = mashStepCollection;
    }

    @XmlTransient
    public Collection<Recipes> getRecipesCollection() {
        return recipesCollection;
    }

    public void setRecipesCollection(Collection<Recipes> recipesCollection) {
        this.recipesCollection = recipesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (scheduleID != null ? scheduleID.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MashSchedule)) {
            return false;
        }
        MashSchedule other = (MashSchedule) object;
        if ((this.scheduleID == null && other.scheduleID != null) || (this.scheduleID != null && !this.scheduleID.equals(other.scheduleID))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.MashSchedule[ scheduleID=" + scheduleID + " ]";
    }
    
}
